package com.jrx.anytxn.param.controller.account;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.param.dto.account.GaProductSummaryInfoRes;
import com.jrx.anytxn.param.dto.account.SubjectSummaryInfoRes;
import com.jrx.anytxn.param.service.account.IGaProductSummaryInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jrx.auth.filter.service.InfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 与页面相关的运营管理的总分核对controller
 *
 * @author yf
 * date 2020/4/16 0016
 * @version V1.0
 **/
@Api("总分核对")
@RestController
@RequestMapping("/param/ProductSummaryInfo")
public class GaProductSummaryInfoController {


    private static final Logger logger = LoggerFactory.getLogger(GaProductSummaryInfoController.class);

    @Autowired
    private IGaProductSummaryInfoService gaProductSummaryInfoService;

    @Resource
    private InfoService infoService;


    @ApiOperation("分页查询总分核对信息")
    @GetMapping("/pageNum/{pageNum}/pageSize/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", required = true)})
    public TxnRespResult<TxnPage<GaProductSummaryInfoRes>> getAllByPage(@PathVariable(value = "pageNum") Integer pageNum, @PathVariable(value = "pageSize") Integer pageSize,
                                                                        @RequestParam String productId,@RequestParam String orgId,@RequestParam String beginDate, @RequestParam String endDate) {
        TxnRespResult<TxnPage<GaProductSummaryInfoRes>> result = new TxnRespResult<>();
        try {
            String tenantId=String.valueOf(infoService.getUser().getProjectId());
            result.getSuccess(gaProductSummaryInfoService.getPageByCondition(pageNum, pageSize,tenantId,productId,orgId,beginDate,endDate));
        } catch (TxnException e) {
            logger.error(e.getMessage(),e);
            result.getFail(e.getErrCode(), e.getMessage());
        }
        return result;
    }


}
